<?php
namespace app\admin\controller;

class Api extends Base2
{
    
    
    function bind(){
        $socket = new \app\index\model\Socket();
        return $socket->bindAdmin($this->uid);
    }
    
    function getResult(){
        $jccount = new \app\index\model\Jccount();
        $data = $jccount->readjc();
        $jc = new \app\admin\model\Jc();
        $res = $jccount->getLock();
        $data['allmoney'] = $jc->getAllMoney2($res);
        return json($data);
    }
    function kaijaing(){
        $file = "jclock.php";
        $fp = fopen($file, "w");
        if (flock($fp, LOCK_EX|LOCK_NB)) {
            
        $jccount = new \app\index\model\Jccount();
        $res = $jccount->getLock();
        if ($res['times']>0){
            flock($fp, LOCK_UN); // 解锁
            fclose($fp);
            return ;
        }
         $jccount->kaijaing();
        }
        flock($fp, LOCK_UN); // 解锁
        fclose($fp);
    }
    function openGame(){
        $jccount = new \app\index\model\Jccount();
        return $jccount->openjc();
    }
    function getNow(){
        $jccount = new \app\index\model\Jccount();
        $res = $jccount->getLock();
        return $this->returnOk($res);
    }
     function getyingli(){
         $str = I('post.num');
         if(!$str&&strlen($str)!=3){
             return $this->param_error();
         }
        
        $jc = new \app\admin\model\Jc();
        $r = $jc->countsyingli($str);
        return $this->returnOk(round(($r['yingli']/100),2));
     }
     function gres() {
         $str = I('post.num');
         if(!$str&&strlen($str)!=3){
             return $this->param_error();
         }
         
         $jc = new \app\admin\model\Jc();
         $r = $jc->countsyingli($str);
         if (!($this->uid)){
             return $this->param_error();
         }
         $jccount = new \app\index\model\Jccount();
         $res = $jccount->getLock();
         $jcqi = D('qi');
         $qiinfo = $jcqi->where("status",0)->where("id",$res['id'])->find();
         if (!$qiinfo) {
             return $this->returnAlert("未找到");
         }
         $qiinfo['result'] = $jc->rand6().$str;
         $qiinfo['total_money'] = $r['total'];
         $qiinfo['yingli_money'] = $r['yingli'];
         $qiinfo['is_hand'] = 1;
         $qiinfo['hand_id'] = $this->uid;
         $jcqi->update($qiinfo);
         return $this->returnOk();
     }
}
